#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include "preloaders.h"

void mole_addpreloaders(lua_State *L)
{
    lua_getglobal(L,"package");
    lua_getfield(L,-1,"preload");
    const luaL_Reg* reg;
    for (reg = preloaders; reg->name; ++reg)
    {
        lua_pushstring(L, reg->name);
        lua_pushcfunction(L, reg->func);
        lua_settable(L,-3);
    }
    lua_pop(L,2); // get rid of package and package.preload
}
